PetCtCSVParser.parseCSV   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 4
1
/**
2
 Copyright (C) 2018-2020 KANOUN Salim
3
 This program is free software; you can redistribute it and/or modify
4
 it under the terms of the Affero GNU General Public v.3 License as published by
5
 the Free Software Foundation;
6
 This program is distributed in the hope that it will be useful,
7
 but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
 Affero GNU General Public Public for more details.
10
 You should have received a copy of the Affero GNU General Public Public along
11
 with this program; if not, write to the Free Software Foundation, Inc.,
12
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
13
 */
14
 class PetCtCSVParser {
15
16
    constructor(csvFile){
17
        this.csvFile = csvFile
18
    }
19
20
    parseCSV(){
21
        let self = this
22
23
        return new Promise(function(complete, error) {
24
            Papa.parse(self.csvFile, {complete, error});
0 ignored issues
show
Bug introduced by
The variable Papa seems to be never declared. If this is a global, consider adding a /** global: Papa */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
        }).then(results => {
26
            self.papaResultArray = results.data
27
        }).then( () => {
28
            self._extractLineOfInterest()
29
        });
30
31
    }
32
33
    _extractLineOfInterest(){
34
        let parsedCSV = this.papaResultArray
35
36
        for(let i = 0 ; i < parsedCSV.length ; i++){
37
            //Search for empty line, the patient identification is just the line before
38
            if( parsedCSV[i].length>1 && parsedCSV[i][1].includes(" sum") ) {
39
                this.patientIdentificationLine = (i+1)
40
            }
41
            if( parsedCSV[i][0]=="SUVlo" ) {
42
                this.roiThresholdLine = (i+1)
43
            }
44
        }
45
        console.log(this.papaResultArray)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
46
    }
47
48
    getTmtvValue(){
49
        return this.papaResultArray[(this.patientIdentificationLine - 1)][3]
50
    }
51
    getPatientId(){
52
        return this.papaResultArray[this.patientIdentificationLine][13]
53
    }
54
55
    getAcquisitionDate(){
56
        let dateString = this.papaResultArray[this.patientIdentificationLine][1].trim()
57
        let date = moment(dateString, "MMM D_YYYY").toDate();
58
        return date
59
    }
60
61
    getSuvLow(){
62
        return this.papaResultArray[this.roiThresholdLine][0]
63
    }
64
65
    getsuvHigh(){
66
        return this.papaResultArray[this.roiThresholdLine][1]
67
    }
68
69
    isUseSUV(){
70
        return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][4]))
71
    }
72
73
    isUseCT(){
74
        return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][5]))
75
    }
76
77
    checkAcquisition(patientId, date){
78
        return (this.getPatientId() == patientId && this.getAcquisitionDate().getTime() === date.getTime())
79
    }
80
81
    checkTMTVThreshold(suvLo, suvHigh=100){
82
        let checkSuvLo = true
83
        if(suvLo != null) checkSuvLo = (this.getSuvLow() == suvLo)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Best Practice introduced by
Comparing suvLo to null using the != operator is not safe. Consider using !== instead.
Loading history...
84
        return ( checkSuvLo && this.getsuvHigh()>=suvHigh && !this.isUseCT() && this.isUseSUV() )
85
    }
86
}
87
88